<a href='https://github.com/angular/angular.js/edit/v1.5.x/src/ngMock/angular-mocks.js?message=docs(ngMock)%3A%20describe%20your%20change...#L2263' class='improve-docs btn btn-primary'><i class="glyphicon glyphicon-edit">&nbsp;</i>Improve this Doc</a>


<h1>
  <code>ngMock</code>
</h1>

<h2>Installation</h2>

  <p>First, download the file:</p>
<ul>
<li><a href="https://developers.google.com/speed/libraries/devguide#angularjs">Google CDN</a> e.g.
<code>&quot;//ajax.googleapis.com/ajax/libs/angularjs/X.Y.Z/angular-mocks.js&quot;</code></li>
<li><a href="https://www.npmjs.com/">NPM</a> e.g. <code>npm install angular-mocks@X.Y.Z</code></li>
<li><a href="http://bower.io">Bower</a> e.g. <code>bower install angular-mocks#X.Y.Z</code></li>
<li><a href="https://code.angularjs.org/">code.angularjs.org</a> (discouraged for production use)  e.g.
<code>&quot;//code.angularjs.org/X.Y.Z/angular-mocks.js&quot;</code></li>
</ul>
<p>where X.Y.Z is the AngularJS version you are running.</p>
<p>Then, configure your test runner to load <code>angular-mocks.js</code> after <code>angular.js</code>.
This example uses <a href="http://karma-runner.github.io/">Karma</a>:</p>
<pre><code>config.set({
  files: [
    &#39;build/angular.js&#39;, // and other module files you need
    &#39;build/angular-mocks.js&#39;,
    &#39;&lt;path/to/application/files&gt;&#39;,
    &#39;&lt;path/to/spec/files&gt;&#39;
  ]
});
</code></pre>
<p>Including the <code>angular-mocks.js</code> file automatically adds the <code>ngMock</code> module, so your tests
 are ready to go!</p>



<h1 id="ngmock">ngMock</h1>
<p>The <code>ngMock</code> module provides support to inject and mock Angular services into unit tests.
In addition, ngMock also extends various core ng services such that they can be
inspected and controlled in a synchronous manner within test code.</p>
<div doc-module-components="ngMock"></div>





<div class="component-breakdown">
  <h2>Module Components</h2>
  
  <div>
    <h3 class="component-heading" id="object">Object</h3>
    <table class="definition-table">
      <tr>
        <th>Name</th>
        <th>Description</th>
      </tr>
      
      <tr>
        <td><a href="api/ngMock/object/angular.mock">angular.mock</a></td>
        <td><p>Namespace from &#39;angular-mocks.js&#39; which contains testing related code.</p>
</td>
      </tr>
      
    </table>
  </div>
  
  <div>
    <h3 class="component-heading" id="provider">Provider</h3>
    <table class="definition-table">
      <tr>
        <th>Name</th>
        <th>Description</th>
      </tr>
      
      <tr>
        <td><a href="api/ngMock/provider/$exceptionHandlerProvider">$exceptionHandlerProvider</a></td>
        <td><p>Configures the mock implementation of <a href="api/ng/service/$exceptionHandler"><code>$exceptionHandler</code></a> to rethrow or to log errors
passed to the <code>$exceptionHandler</code>.</p>
</td>
      </tr>
      
    </table>
  </div>
  
  <div>
    <h3 class="component-heading" id="service">Service</h3>
    <table class="definition-table">
      <tr>
        <th>Name</th>
        <th>Description</th>
      </tr>
      
      <tr>
        <td><a href="api/ngMock/service/$exceptionHandler">$exceptionHandler</a></td>
        <td><p>Mock implementation of <a href="api/ng/service/$exceptionHandler"><code>$exceptionHandler</code></a> that rethrows or logs errors passed
to it. See <a href="api/ngMock/provider/$exceptionHandlerProvider">$exceptionHandlerProvider</a> for configuration
information.</p>
</td>
      </tr>
      
      <tr>
        <td><a href="api/ngMock/service/$log">$log</a></td>
        <td><p>Mock implementation of <a href="api/ng/service/$log"><code>$log</code></a> that gathers all logged messages in arrays
(one array per logging level). These arrays are exposed as <code>logs</code> property of each of the
level-specific log function, e.g. for level <code>error</code> the array is exposed as <code>$log.error.logs</code>.</p>
</td>
      </tr>
      
      <tr>
        <td><a href="api/ngMock/service/$interval">$interval</a></td>
        <td><p>Mock implementation of the $interval service.</p>
</td>
      </tr>
      
      <tr>
        <td><a href="api/ngMock/service/$animate">$animate</a></td>
        <td><p>Mock implementation of the <a href="api/ng/service/$animate"><code>$animate</code></a> service. Exposes two additional methods
for testing animations.</p>
</td>
      </tr>
      
      <tr>
        <td><a href="api/ngMock/service/$httpBackend">$httpBackend</a></td>
        <td><p>Fake HTTP backend implementation suitable for unit testing applications that use the
<a href="api/ng/service/$http">$http service</a>.</p>
</td>
      </tr>
      
      <tr>
        <td><a href="api/ngMock/service/$timeout">$timeout</a></td>
        <td><p>This service is just a simple decorator for <a href="api/ng/service/$timeout">$timeout</a> service
that adds a &quot;flush&quot; and &quot;verifyNoPendingTasks&quot; methods.</p>
</td>
      </tr>
      
      <tr>
        <td><a href="api/ngMock/service/$controller">$controller</a></td>
        <td><p>A decorator for <a href="api/ng/service/$controller"><code>$controller</code></a> with additional <code>bindings</code> parameter, useful when testing
controllers of directives that use <a href="api/ng/service/$compile#-bindtocontroller-"><code>bindToController</code></a>.</p>
</td>
      </tr>
      
      <tr>
        <td><a href="api/ngMock/service/$componentController">$componentController</a></td>
        <td><p>A service that can be used to create instances of component controllers.</p>
<div class="alert alert-info">
Be aware that the controller will be instantiated and attached to the scope as specified in
the component definition object. If you do not provide a <code>$scope</code> object in the <code>locals</code> param
then the helper will create a new isolated scope as a child of <code>$rootScope</code>.
</div></td>
      </tr>
      
    </table>
  </div>
  
  <div>
    <h3 class="component-heading" id="type">Type</h3>
    <table class="definition-table">
      <tr>
        <th>Name</th>
        <th>Description</th>
      </tr>
      
      <tr>
        <td><a href="api/ngMock/type/angular.mock.TzDate">angular.mock.TzDate</a></td>
        <td><p><em>NOTE</em>: this is not an injectable instance, just a globally available mock class of <code>Date</code>.</p>
</td>
      </tr>
      
      <tr>
        <td><a href="api/ngMock/type/$rootScope.Scope">$rootScope.Scope</a></td>
        <td><p><a href="api/ng/type/$rootScope.Scope">Scope</a> type decorated with helper methods useful for testing. These
methods are automatically available on any <a href="api/ng/type/$rootScope.Scope">Scope</a> instance when
<code>ngMock</code> module is loaded.</p>
</td>
      </tr>
      
    </table>
  </div>
  
  <div>
    <h3 class="component-heading" id="function">Function</h3>
    <table class="definition-table">
      <tr>
        <th>Name</th>
        <th>Description</th>
      </tr>
      
      <tr>
        <td><a href="api/ngMock/function/angular.mock.dump">angular.mock.dump</a></td>
        <td><p><em>NOTE</em>: This is not an injectable instance, just a globally available function.</p>
</td>
      </tr>
      
      <tr>
        <td><a href="api/ngMock/function/angular.mock.module">angular.mock.module</a></td>
        <td><p><em>NOTE</em>: This function is also published on window for easy access.<br>
<em>NOTE</em>: This function is declared ONLY WHEN running tests with jasmine or mocha</p>
</td>
      </tr>
      
      <tr>
        <td><a href="api/ngMock/function/angular.mock.module.sharedInjector">angular.mock.module.sharedInjector</a></td>
        <td><p><em>NOTE</em>: This function is declared ONLY WHEN running tests with jasmine or mocha</p>
</td>
      </tr>
      
      <tr>
        <td><a href="api/ngMock/function/angular.mock.inject">angular.mock.inject</a></td>
        <td><p><em>NOTE</em>: This function is also published on window for easy access.<br>
<em>NOTE</em>: This function is declared ONLY WHEN running tests with jasmine or mocha</p>
</td>
      </tr>
      
    </table>
  </div>
  
</div>





